<?php 
/**
 * This file is part of DomFg.
 * 
 * DomFg is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * DomFg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with DomFg.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @link http://inditel.ee/
 * @copyright 2007-2009 Inditel Meedia OÜ
 * @author Oliver Leisalu <oliver@inditel.ee>
 */

/**
* @author Oliver Leisalu, Inditel Meedia
* @package DomFg
* @subpackage Panel
*/
class DomFgPanel extends DomFgComponent {

	protected $title;
	
	protected $name;

	protected $items = array();

	protected $buttons = array();
	
	protected $headerButtons = array();
	
	protected $layout = 'none';

	protected $layoutConfig = array();
	
	protected $action = '';
	
	protected $scripts = array();
	
	protected $border = true;
	
	protected $frame = true;
	
	protected $isForm = false;
	
	protected $closable = false;
	
	protected $closed = false;
	
	protected $bodyStyle = '';
	
	protected $html;
	
	
	public function __construct() {
	
	}
	
	
	
	
	public function title( $value ) {
		$this->title = $value;
		return $this;
	}
	
	public function border( $value ) {
		$this->border = (bool)$value;
		return $this;
	}
	
	public function frame( $value ) {
		$this->frame = (bool)$value;
		return $this;
	}
	
	public function closable( $value ) {
		$this->closable = (bool)$value;
		return $this;
	}
	
	public function closed( $value ) {
		$this->closed = (bool)$value;
		return $this;
	}
	
	public function name( $name ) {
		$this->name = $name;
		return $this;
	}
	
	public function scripts( array $scripts ) {
		$this->scripts = $scripts;
		return $this;
	}
	
	public function bodyStyle( $bodyStyle ) {
		$this->bodyStyle = $bodyStyle;
		return $this;
	}
	
	public function html( $html ) {
		$this->html = $html;
		return $this;
	}
	
	public function action( $action ) {
		$this->action = $action;
		$this->isForm = true;
		return $this;
	}
	
	public function isForm( $value = true ) {
		$this->isForm = (bool)$value;
		return $this;
	}
	
	public function layout( $layout ) {
		$this->layout = (string)$layout;
		return $this;
	}
	
	final public function layoutConfig( array $layoutConfig ) {
		$this->layoutConfig = $layoutConfig;
		return $this;
	}
	
		
		
		
	public function addItem( DomFgComponent $item ) {
		return $this->items[] = $item;
	}
	
	public function addButton( DomFgButton $button ) {
		return $this->buttons[] = $button;
	}
	
	public function addHeaderButton( DomFgButton $button ) {
		return $this->headerButtons[] = $button;
	}
	
	
	
	
	
	public function render() {
	
		$r = new DomSmarty();
		$r->template_dir = DomFg::getTemplatePath();
		$r->assign('templateUrl', DomFg::getTemplateUrl() );
		
		$r->assign('panel', $this );
		$r->assign('contents', DomFgLayout::render($this) );
		
		$buttons = '';
		foreach( $this->buttons as $button ) $buttons .= $button->render();
		$r->assign('buttons', $buttons );
		
		$headerButtons = '';
		foreach( $this->headerButtons as $button ) $headerButtons .= $button->render();
		$r->assign('headerButtons', $headerButtons );

		$r->assign('fields', DomFgPost::getInstance()->getFields() );
	
		return $r->fetch('panel.html');
	}
	
	public static function getDefaultChild() {
		return 'title';
	}
	
	
	
}
?>